#!/usr/bin/env bash

#########################################
# THIS MODULE ONLY SHOWS THE HELP MESSAGE
#########################################

function _help_head() {
	printf '
               _____                    _____
              /\    \                  /\    \		   A	   A
             /::\    \                /::\____\		    P	    M
            /::::\    \              /::::|   |		     P
           /::::::\    \            /:::::|   |		      M	      &
          /:::/\:::\    \          /::::::|   |		       A
         /:::/__\:::\    \        /:::/|::|   |		        N
        /::::\   \:::\    \      /:::/ |::|   |
       /::::::\   \:::\    \    /:::/  |::|___|______
      /:::/\:::\   \:::\    \  /:::/   |::::::::\    \
     /:::/  \:::\   \:::\____\/:::/    |:::::::::\____\
     \::/    \:::\  /:::/    /\::/    / ~~~~~/:::/    /
      \/____/ \:::\/:::/    /  \/____/      /:::/    /
               \::::::/    /               /:::/    /
                \::::/    /               /:::/    /
                /:::/    /               /:::/    /╔═╗╔╗╔┌─┐┌─┐┌─┐┬─┐
               /:::/    /               /:::/    / ╠═╣║║║├─┤│ ┬├┤ ├┬┘
              /:::/    /               /:::/    /  ╩ ╩╝╚╝┴ ┴└─┘└─┘┴└─
             /:::/    /╔═╗╔═╗┬  ┬┌─┐┌─┐┌┬┐┬┌─┐┌┐┌
             \::/    / ╠═╝╠═╝│  ││  ├─┤ │ ││ ││││
              \/____/  ╩  ╩  ┴─┘┴└─┘┴ ┴ ┴ ┴└─┘┘└┘	by Ivan Alex HC

  >> 𝘋𝘢𝘵𝘢𝘣𝘢𝘴𝘦 & 𝘴𝘰𝘭𝘶𝘵𝘪𝘰𝘯𝘴 𝘧𝘰𝘳 𝘢𝘭𝘭 𝘈𝘱𝘱𝘐𝘮𝘢𝘨𝘦𝘴 𝘢𝘯𝘥 𝘱𝘰𝘳𝘵𝘢𝘣𝘭𝘦 𝘢𝘱𝘱𝘴 𝘧𝘰𝘳 𝘎𝘕𝘜/𝘓𝘪𝘯𝘶𝘹 <<

 ##########################################################################'
}

function _help_body() {
	printf '
 ___________________________________________________________________________

 CLIENT/VERSION: "'"$(echo "$AMCLI" | tr a-z A-Z)"'" v'"$($AMCLIPATH -v)"'

 USAGE:	'$AMCLI' {OPTION}

 	'$AMCLI' {OPTION} {PROGRAM}
 __________________________________________________________________________

 ##########################################################################
 __________________________________________________________________________

 				OPTIONS

 		(standard, for both "AM" AND "APPMAN")
 __________________________________________________________________________
 __________________________________________________________________________

 -a, about

 SYNOPSIS:	-a {PROGRAM}

 DESCRIPTION: 	Shows more info about one or more apps.
 __________________________________________________________________________

 -b, backup

 SYNOPSIS:	-b {PROGRAM}

 DESCRIPTION:	Save the current version of one or more apps.

 Snapshots are stored in $HOME/.am-snapshots/$PROGRAM.

 To restore the snapshots see the "-o" option.
 __________________________________________________________________________

 -c, clean

 SYNOPSIS:	-c

 DESCRIPTION:	Removes all the unnecessary files and folders.
 __________________________________________________________________________

 -C, --config

 SYNOPSIS:	-C {PROGRAM}

 DESCRIPTION:	Set a dedicated $XDD_CONFIG_HOME for one or more AppImages.
 __________________________________________________________________________

 -d, download

 SYNOPSIS:	-d {PROGRAM}
 		-d --convert {PROGRAM}

 DESCRIPTION:	Download one or more installation scripts to your desktop.

 With the option "--convert" its converted to a standalone local installer,

 but AM requires AppMan to be installed to add custom directory settings.
 __________________________________________________________________________

 -e, extra

 SYNOPSIS:	-e user/project {APPNAME}
 		-e user/project {APPNAME} {KEYWORD}

 DESCRIPTION:	Install AppImages from github.com, outside the database.

 This allows you to install, update and manage them all like the others.

 Where "user/project" can be the whole URL to the github repository,

 give a name to the program so that it can be used from the command line.

 Optionally, add an "univoque" keyword if multiple AppImages are listed.
 __________________________________________________________________________

 -f, files

 SYNOPSIS:	-f
 		-f --byname
 		-f --less

 DESCRIPTION:	Shows the list of all installed programs, with sizes.

 By default apps are sorted by size, use "--byname" to sort by name.

 With the option "--less" it shows only the number of installed apps.
 __________________________________________________________________________

 -h, help

 SYNOPSIS:	-h

 DESCRIPTION:	Prints this message.
 __________________________________________________________________________

 -H, --home

 SYNOPSIS:	-H {PROGRAM}

 DESCRIPTION:	Set a dedicated $HOME directory for one or more AppImages.
 __________________________________________________________________________

 -i, install

 SYNOPSIS:	-i {PROGRAM}
 		-i --debug {PROGRAM}
 		-i --force-latest {PROGRAM}

 DESCRIPTION:	Install one or more programs or libraries from the list.

 With the "--debug" option you can see log messages to debug the script.

 For more details on "--force-latest", see the dedicated option, below.
 __________________________________________________________________________

 -l, list

 SYNOPSIS:	-l

 DESCRIPTION:	Shows the list of all the apps available in the repository.
 __________________________________________________________________________

 -o, overwrite

 SYNOPSIS:	-o {PROGRAM}

 DESCRIPTION:	Overwrite apps with snapshots saved previously (see "-b").
 __________________________________________________________________________

 -q, query

 SYNOPSIS:	-q {KEYWORD}
 		-q --pkg {PROGRAM1} {PROGRAM2}

 DESCRIPTION:	Search for keywords in the list of available applications.

 Add the "--pkg" option to search only the names of one or more apps.
 __________________________________________________________________________

 -r, remove

 SYNOPSIS:	-r {PROGRAM}

 DESCRIPTION:	Removes one or more apps, requires confirmation.
 __________________________________________________________________________

 -R

 SYNOPSIS:	-R {PROGRAM}

 DESCRIPTION:	Removes one or more apps without asking.
 __________________________________________________________________________

 -s, sync

 SYNOPSIS:	-s

 DESCRIPTION:	Updates this script to the latest version hosted.
 __________________________________________________________________________

 -t, template

 SYNOPSIS:	-t {PROGRAM}

 DESCRIPTION:	Generate a custom installation script.

 You can install it using the "'$AMCLI' -i /path/to/your-script" command.
 __________________________________________________________________________

 -u, -U, update

 SYNOPSIS:	-u
 		-u --apps
 		-u {PROGRAM}

 DESCRIPTION:	Update all the apps (and "'$AMCLI'" itself) or just one.

 If you add the "--apps" suboption you only update apps.
 __________________________________________________________________________

 -v, version

 SYNOPSIS:	-v

 DESCRIPTION:	Shows the version.
 __________________________________________________________________________

 --devmode-disable

 SYNOPSIS:	--devmode-disable

 DESCRIPTION:	Undo "--devmode-enable" (see below).
 __________________________________________________________________________

 --devmode-enable

 SYNOPSIS:	--devmode-enable

 DESCRIPTION:	Use the development branch (at your own risk).
 __________________________________________________________________________

 --disable-completion

 SYNOPSIS:	--disable-completion

 DESCRIPTION:	Disable bash-completion.
 __________________________________________________________________________

 --disable-sandbox

 SYNOPSIS:	--disable-sandbox {PROGRAM}

 DESCRIPTION:	Disable the sandbox for the selected app.
 __________________________________________________________________________

 --enable-completion

 SYNOPSIS:	--enable-completion

 DESCRIPTION:	Enable bash-completion.
 __________________________________________________________________________

 --force-latest

 SYNOPSIS:	--force-latest {PROGRAM}
 		-i --force-latest {PROGRAM}

 DESCRIPTION:	Downgrades an installed app from pre-release to "latest".

 This can be used with "-i" to force the installation of apps from "latest".

 Many scripts point to "releases" to find the latest build for GNU/Linux if

 the developer has not uploaded one in "latest".
 __________________________________________________________________________

 --launcher

 SYNOPSIS:	--launcher /path/to/${APPIMAGE}

 DESCRIPTION:	Embed one or more local AppImages in the applications menu.

 This will also create a script to launch AppImage from $PATH as "binary".

 I suggest dragging the files into the terminal to get the desired effect.
 __________________________________________________________________________

 --rollback, downgrade

 SYNOPSIS:	--rollback {PROGRAM}

 DESCRIPTION:	Download an older or specific app version.
 __________________________________________________________________________

 --sandbox

 SYNOPSIS:	--sandbox {PROGRAM}

 DESCRIPTION:	Run an AppImage in a sandbox using Aisap.
 __________________________________________________________________________

 apikey

 SYNOPSIS:	apikey {Github Token}
 		apikey delete

 DESCRIPTION:	Accede to github APIs using your personal access tokens.

 The configuration file named "ghapikey.txt" will be saved in '$AMPATH'.

 Use the command "'$AMCLI' apikey delete/del/remove" to remove the file.
 __________________________________________________________________________

 lock

 SYNOPSIS:	lock {PROGRAM}

 DESCRIPTION:	Lock the selected app to the current version installed.

 Only works if exists a dedicated "AM-updater" installed with the app.
 __________________________________________________________________________

 neodb

 SYNOPSIS:	neodb
 		newrepo --silent

 DESCRIPTION:	Add third-party repos to extend the existing database.

 Use "--silent" to hide messages about third-party repos in use.
 __________________________________________________________________________

 newrepo

 SYNOPSIS:	newrepo {URL}
 		newrepo {PATH}
 		newrepo off
 		newrepo on

 DESCRIPTION:	Set the variable "$AMREPO" to a new custom repository.

 Use "off" to restore the default one or overwrite it with a new one.
 __________________________________________________________________________

 nolibfuse

 SYNOPSIS:	nolibfuse {PROGRAM}

 DESCRIPTION:	Convert an installed Type2 AppImage to a Type3 AppImage.

 Type3 AppImages does not require libfuse2 installed.
 __________________________________________________________________________

 unlock

 SYNOPSIS:	unlock {PROGRAM}

 DESCRIPTION:	Unlock updates for the selected program (nulls "lock").
 __________________________________________________________________________
 __________________________________________________________________________

 			       EXTRA OPTIONS
 __________________________________________________________________________

 --system

 SYNOPSIS:	--system

 DESCRIPTION:	Switch "AM" back to "AM" from "AppMan Mode" (see --user).
 __________________________________________________________________________

 --user, appman				( only works with "AM" )

 SYNOPSIS:	--user

 DESCRIPTION:	Run "AM" as an unprivileged user making it act as "AppMan".
 __________________________________________________________________________

 ##########################################################################'
}

function _help_footer() {
	printf '

 SITES:

 https://github.com/IVAN-HC/AM

 https://github.com/IVAN-HC/APPMAN

 ##########################################################################'
}

function _help() {
	_help_head
	_help_body
	_help_footer | less
}

_help | less
